package de.koller.pulsar.scene.planet;

import de.koller.aframe.util.math.interpolation.CubicInterpolation;
import de.koller.aframe.util.misc.ColorOperations;
import java.awt.Point;

public class StarRender {

	public Context renderContext( float starX, float starY, float brightness, float radius, int color ) {
		return new Context( starX, starY, brightness, radius, color );
	}
	
	public class Context {
		private final float starX, starY;
		private final float brightness, radius;
		private final int color;

		public Context( float starX, float starY, float brightness, float radius, int color ) {
			this.starX = starX;
			this.starY = starY;
			this.brightness = brightness;
			this.radius = radius;
			this.color = color;
		}
		
		public int colorAt( float x, float y ) {
			double d = Point.distance( x, y, starX, starY );
			float spike = Math.abs( starX - x ) * Math.abs( starY - y );

			d += spike * brightness * 0.01f;
			
			if( d > radius + brightness )
				return 0xff_000000;
			
			float k = CubicInterpolation.cubic( 1f / (brightness+radius) * (float)d, 7f, 1f, 0f, 1f );
			
			return ColorOperations.setA( ColorOperations.mult( color, k ), 0xff );
		}
		
	}
	
}
